package com.glasses.primework;

import java.io.InputStream;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

@ManagedBean
public class FileDownloadBean {
    private StreamedContent file;
    
    public FileDownloadBean() {
        InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("/IMG/photo2.jpg");
        file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_photo2.jpg");
    }
    
    public StreamedContent getFile() {
        System.out.println("FileDownloadBean.getFile() = " + file);
        return file;
    }
}
